package com.yanjiali.controller;

import com.yanjiali.enumerate.LoginTypeEnum;
import com.yanjiali.model.R;
import com.yanjiali.model.req.LogOutReq;
import com.yanjiali.model.resp.LogOutResp;
import com.yanjiali.service.SysUserService;
import com.yanjiali.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Package: com.yanjiali.controller
 * @Author: yanjiali
 * @Created: 2025/4/14 18:53
 */
@RestController
@Api(tags = "登出控制器")
@RequestMapping("/v1")
public class LogOutController {
    @Autowired
    private SysUserService sysUserService;  //系统用户，管理员

    @Autowired
    private UserService userService;    //普通用户

    @PostMapping("/logOut")
    @ApiOperation("用户登出接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "logOutReq", value = "登出请求参数")
    })
    public R<LogOutResp> login(@RequestBody LogOutReq logOutReq) {
        String loginType = logOutReq.getLoginType().trim();
        if (loginType.equals(LoginTypeEnum.ADMIN_TYPE.getLoginType())) {
            return sysUserService.logOut(logOutReq);
        }else if(loginType.equals(LoginTypeEnum.MEMBER_TYPE.getLoginType())) {
            return userService.logOut(logOutReq);
        }else {
            return R.fail("未知的登录类型");
        }
    }
}
